package com.moon.interview.utils;

import cn.dev33.satoken.stp.StpUtil;
import com.moon.interview.exception.SysErrorCode;
import com.moon.interview.exception.ApplicationException;
import com.moon.interview.model.entity.User;

import java.util.Objects;

import static com.moon.interview.constant.UserConstant.USER_LOGIN_STATE;

public class UserUtils {

    public static User getLoginUser(){
        // 获取当前登录信息
        Object loginId = StpUtil.getLoginIdDefaultNull();
        if (Objects.isNull(loginId)) {
            throw new ApplicationException(SysErrorCode.NOT_LOGIN_ERROR, "未登录");
        }
        return (User) StpUtil.getSessionByLoginId(loginId).get(USER_LOGIN_STATE);
    }
}
